﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Security;

namespace WS.EKA.Web.UI.Pages
{
    public partial class Login : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
        }

        protected void LoginBtn_Click(object sender, EventArgs e)
        {
            var name = this.UserName.Text;
            var pwd = this.Password.Text;
            var user = GetLoginUser();
            if (user.Name != name ||user.Password!= pwd)
            {
                WebMessageBox(this, "用户名或密码错误");
                return;
            }
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.Name, DateTime.Now,
                DateTime.MaxValue, false, user.Name, FormsAuthentication.FormsCookiePath);
            // Encrypt the ticket.
            string encTicket = FormsAuthentication.Encrypt(ticket);
            // Create the cookie.
            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
            cookie.HttpOnly = true;
            Response.Cookies.Add(cookie);
            // Redirect back to original URL.
            string ret = FormsAuthentication.GetRedirectUrl(user.Name, true);
            Response.Redirect(ret);
        }

        protected void ChangePwdBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("changepassword.aspx");
        }
    }
}